local assets =
{
    -- Asset("ANIM", "anim/panda_fisherman_supply_pack.zip"),
    -- Asset( "IMAGE", "images/inventoryimages/panda_fisherman_supply_pack.tex" ),  -- 背包贴图
    -- Asset( "ATLAS", "images/inventoryimages/panda_fisherman_supply_pack.xml" ),
}
local function GetStringsTable()
    return TUNING.NPC_CHAT_TABLE[ type(TUNING.__NPC_LANGUAGE)=="function" and TUNING.__NPC_LANGUAGE() or TUNING.__NPC_LANGUAGE ] ["npc_event_pigman_arena"] or {}
end
local function spellfn(inst)
    local points = inst.npc_base_lib:GetSurroundPoints({
        range = 13,
        num = 25
    })
    --------- 检查区域是否全在陆地上
    -- TheWorld.Map:IsAboveGroundAtPoint(get_pt.x,get_pt.y,get_pt.z,false)
    for k, pt in pairs(points) do
        if TheWorld.Map:IsAboveGroundAtPoint(pt.x,pt.y,pt.z,false) == false then            
            inst.npc_base_lib:Wisper(GetStringsTable().spell_failed)
            return false
        end
    end

    local pt = Vector3(inst.Transform:GetWorldPosition())
    local ents = TheSim:FindEntities(pt.x,0,pt.z,20,{"npc_item_pigman_arena_event_start"},nil,nil)
    if #ents > 0 then
        return false
    end
    
    SpawnPrefab("npc_item_pigman_arena_event_start"):PushEvent("Set",{
        pt = pt
    })
    inst:Remove()
end


local function fn()
    local inst = CreateEntity()

    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    MakeInventoryPhysics(inst)

    inst.AnimState:SetBank("pig_coin")
    inst.AnimState:SetBuild("pig_coin")
    inst.AnimState:PlayAnimation("idle")

	MakeInventoryFloatable(inst, "small")

    inst:AddTag("cointosscast") -- for coint toss casting
    TheSim:LoadPrefabs({ "quagmire_swampig" })
    inst.entity:SetPristine()
    if not TheWorld.ismastersim then
        return inst
    end

    inst.fxcolour = {248/255, 248/255, 198/255}
    inst.castsound = "dontstarve/pig/mini_game/cointoss"

    inst:AddComponent("npc_base_lib")


    inst:AddComponent("inspectable") --可检查组件
    
    inst:AddComponent("inventoryitem")
    inst.components.inventoryitem:ChangeImageName("pig_coin")
	inst.components.inventoryitem.cangoincontainer = true


    inst:AddComponent("named")
    -- inst.components.named:SetName(tostring(_table.Name))
    inst.components.named:SetName(GetStringsTable().coin_name)
    STRINGS.CHARACTERS.GENERIC.DESCRIBE[string.upper("npc_item_pigman_arena_spell_coin")] = GetStringsTable().inspect_str  --人物检查的描述

    inst:AddComponent("spellcaster")
    inst.components.spellcaster:SetSpellFn(spellfn)
    inst.components.spellcaster.canusefrominventory = true


    return inst
end

return Prefab("npc_item_pigman_arena_spell_coin", fn,assets)